package mailTest;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class ff {
	public static void main(String args[]) throws Exception 
    { 

        String host = "smtp.sina.com.cn"; 
        String from =  "jovi0329@sina.com"; 
        String to = "zhuwei@zhongsou.com"; 
        String username = "jovi0329"; 
        String password = "865405"; 

        // Get system properties 
        // Properties props = System.getProperties(); 很多例子中是这样的，其实下面这句更好，可以用在applet中 
        Properties props = new Properties(); 

        // Setup mail server 
        props.put("mail.smtp.host", host); 
        props.put("mail.smtp.auth", "true"); //这样才能通过验证 

        // Get session 
        Session session = Session.getDefaultInstance(props); 

        // watch the mail commands go by to the mail server 
        session.setDebug(true); 

        // Define message 
        MimeMessage message = new MimeMessage(session); 
        message.setFrom(new InternetAddress(from)); 
        message.addRecipient(Message.RecipientType.TO, 
          new InternetAddress(to)); 
        message.setSubject("收到了吧~~"); 
        message.setText("这个还是能实现的，呵呵..<a href='www.baidu.com'>baidu</a>."); 
        // Send message 
        message.saveChanges(); 
        Transport transport = session.getTransport("smtp"); 
        transport.connect(host, username, password); 
        transport.sendMessage(message, message.getAllRecipients()); 
        transport.close(); 
    } 
}
